<?php

/**
 * @author hungnq@younetco.com
 */
class Tab_Form_Order extends YouNet_Form
{
    protected $_element_decorators = array(
        'ViewHelper', 'Errors',
        array('HtmlTag', array('tag' => 'dd')),
		array('Label', array('tag' => 'dt'))
    );
    protected $_button_decorators = array(
        'ViewHelper', 'Errors',
		array(array('data'=>'HtmlTag'), array('tag' => 'dd'))
	);
    protected function _validateStringLength($label, $max, $encoding = 'UTF-8')
    {
        $maxLengthValidator = new Zend_Validate_StringLength(array('max' => $max));
        $maxLengthValidator->setEncoding($encoding);
		$maxLengthValidator->setMessage(sprintf(YouNet_Util::translate('ERROR_IS_TOO_LONG'), $label, $max),Zend_Validate_StringLength::TOO_LONG);
        return $maxLengthValidator;
    }
    public function init()
	{
		$this->setMethod('post');

		$this->setAttrib('class','form_order_info');
		
		$this->addElement('text', 'user_name', array(
            'label' => 'LABEL_FULL_NAME',
			'decorators' => $this->_element_decorators,
			'class' => 'full_name',
            'required' => true,
			'filters' => array('StringTrim')
		));
        $this->user_name->addValidator($this->_validateStringLength(YouNet_Util::translate('LABEL_FULL_NAME'), 255));
        
        $this->addElement('text', 'user_email', array(
            'label' => 'LABEL_EMAIL',
			'decorators' => $this->_element_decorators,
			'class' => 'email',
            'required' => true,
			'filters' => array('StringTrim')
		));
        $this->getElement('user_email')->addValidator('regex', true, array('/^[\w\d\-\_\.]+\@([\w\d\-]+\.){1,2}[\w\d]+$/'))
                ->addErrorMessage('ERROR_UNACCEPTABLE_USER_EMAIL');
        
        $this->addElement('text', 'user_phone', array(
            'label' => 'LABEL_PHONE_NUMBER',
			'decorators' => $this->_element_decorators,
			'class' => 'phone_number',
            'required' => true,
			'filters' => array('StringTrim')
		));
        $this->user_phone->addValidator($this->_validateStringLength(YouNet_Util::translate('LABEL_PHONE_NUMBER'), 255));
        
        $this->addElement('text', 'user_location', array(
            'label' => 'LABEL_LOCALE',
			'decorators' => $this->_element_decorators,
			'class' => 'locale',
            'required' => true,
			'filters' => array('StringTrim')
		));
        $this->user_location->addValidator($this->_validateStringLength(YouNet_Util::translate('LABEL_LOCALE'), 255));
        
        $this->addElement('textarea', 'user_note', array(
            'label' => 'LABEL_NOTE',
			'decorators' => $this->_element_decorators,
			'class' => 'content',
			'filters' => array('StringTrim')
		));
        $this->user_note->addValidator($this->_validateStringLength(YouNet_Util::translate('LABEL_NOTE'), 1000));
		
        $this->addElement('submit', 'btn_checkout', array(
			'label' => 'LABEL_CHECKOUT',
			'class' => 'btn_send',
			'decorators' => $this->_button_decorators
		));
	}

}
